/**************************/
/* author:HuZiya          */
/* Email:297979580@qq.com */
/* DateTime:201809121727  */
/**************************/



$(document).ready(function(){

	function Ajax_zhgl_lb(){
		var start_date_lbt = "2017-06-28";
		var end_date_lbt = "2019-09-01";
		var data = {
			"page_no": "",
			"page_size": "",
			"agent_account": "",
			"mobile": "",
			"start_date":start_date_lbt,
			"end_date":end_date_lbt
		};
		$.ajax({
			url:"/getAdminList",
			type:"get",
			data:data,
			success:function(data) {
				console.log(data)
				//等待遍历
				var html = "";
				$.each(data.data.data,function(i,value){
					html+="<tr id= 'tr_" + i + "'>"+	
					'<td class="td_0">'+
					'<input type="checkbox" class="form-control" id="td_0_input">'+
					'</td>'+
					"<td class='td_1 disn'>"+value.agent_id+"</td>"+
					"<td class='td_2'>"+value.agent_account+"</td>"+
					"<td class='td_3 disn'>"+value.password+"</td>"+
					"<td class='td_4'>"+value.role_name+"</td>"+
					"<td class='td_5'>"+value.mobile+"</td>"+
					"<td class='td_6'>"+value.created_at+"</td>"+
					"<td class='td_7 disn'>"+value.price_c+"</td>"+
					'<td class="td_8">'+
					'<input class="btn btn_bj" value="操作日志" type="button">'+
					'</td>'+
					"</tr>";
					$("#tbod_li").html(html);
				});
			}
		});
	}
	Ajax_zhgl_lb();//获取列表走一波




//列表查询
	$(".btn_cxlb").click(function(){
		var start_date_lbt = $("#start_date_lbt").val();
		var end_date_lbt = $("#end_date_lbt").val();
		var data = {
			"page_no": "",
			"page_size": "",
			"agent_account": "",
			"mobile": "",
			"start_date":start_date_lbt,
			"end_date":end_date_lbt
		};
		console.log(data);
		$.ajax({
			url:"/getAdminList",
			type:"get",
			data:data,
			success:function(data) {
				console.log(data.data.data);
				//等待遍历
				var html = "";
				$.each(data.data.data,function(i,value){
					html+="<tr id= 'tr_" + i + "'>"+	
					'<td class="td_0">'+
					'<input type="checkbox" class="form-control" id="td_0_input">'+
					'</td>'+
					"<td class='td_1 disn'>"+value.agent_id+"</td>"+
					"<td class='td_2'>"+value.agent_account+"</td>"+
					"<td class='td_3 disn'>"+value.password+"</td>"+
					"<td class='td_4'>"+value.role_name+"</td>"+
					"<td class='td_5'>"+value.mobile+"</td>"+
					"<td class='td_6'>"+value.created_at+"</td>"+
					"<td class='td_7 disn'>"+value.price_c+"</td>"+
					'<td class="td_8">'+
					'<input class="btn btn_bj" value="操作日志" type="button">'+
					'</td>'+
					"</tr>";
					$("#tbod_li").html(html);
				});
			}
		});
	})




	//添加用户 bebin
	$(".btn_tjyh").click(function(){
		$(".pos_fixm_xg").fadeOut();
		$(".pos_fixm_tjyh").fadeIn();
	});//.删除打开.pos_fixm_tjyh
	$("#tjyh_sub").click(function(){
        $("#tjyh_sub").attr('disabled',true);
		var agent_account = $("#agent_account_tjyh").val();
		var password = $("#password_tjyh").val();
		var mobile = $("#mobile_tjyh").val();
		var remark = $("#remark_tjyh").val();
		var role_id = $("#role_id_tjyh").val();
		var _token = $("#_token").val();
		var data = {
			"agent_account":agent_account,
			"password":password,
			"mobile":mobile,
			"role_id":role_id,
			"remark":remark,
			"_token":_token
		}
		console.log(data)
		$.ajax({//通知消息获取填充 begin
			type:"post",
			url:"/addAdminAccount",
			data:data,
			success:function(data){
                $("#tjyh_sub").attr('disabled',false);
				// console.log(data.error_code);
				var err_cod = data.error_code;
				if (err_cod == 0){
					$(".pos_fixm_tjyh").fadeOut();//关闭
					alert("添加帐号成功~")
                    Ajax_zhgl_lb();
				}
				else{
					alert("出错了哟~")
				}
			}
		});//通知消息获取填充 end
	});//#xg_sub提交ajax请求 end
	$("#tjyh_x").click(function(){ 
		$(".pos_fixm_tjyh").fadeOut();
	});
	$("#tjyh_q").click(function(){ 
		$(".pos_fixm_tjyh").fadeOut();
	});//.叉叉+.取消关闭.pos_fixm_tjyh end





//操作日志 gebin
	$("#tbod_li").on("click",".btn_bj",function(){
		$(".pos_fixm_tjyh").fadeOut();
		$(".pos_fixm_xg").fadeIn();
		//.操作日志打开.pos_fixm_xg
		agent_id_rz = $(this).parent().siblings(".td_1").html();//获取this id
		var data = {
			// "page_no": "1",
			// "page_size": 25,
			"agent_id":agent_id_rz,
			// "start_date":"2018-06-28",
			// "end_date":"2018-09-01"
		}
		$.ajax({
			url:"/getOpLogList",
			type:"get",
			data:data,
			success:function(data){
				console.log(data);
				//等待遍历(权限不足)
				var html = "";
				$.each(data.data.data,function(i,value){
					html+="<tr id= 'tr_" + i + "'>"+	
					"<td class='td_1'>"+value.agent_id+"</td>"+
					"<td class='td_2'>"+value.created_at+"</td>"+
					"<td class='td_3'>"+value.created_at+"</td>"+
					"<td class='td_4'>"+value.op_log+"</td>"+
					"</tr>";
					$("#tbod_li_rz").html(html);
				});
			}
		});
	});//#xg_sub提交ajax请求 end
	$("#xg_x").click(function(){ 
		$(".pos_fixm_xg").fadeOut();
		$("#tbod_li_rz").html("无数据");
	});

	

	//日志查询
	$(".btn_cxrz").click(function(){
		var start_date_lbt = $("#start_date_rzt").val();
		var end_date_lbt = $("#end_date_rzt").val();
		var data = {
			// "page_no": "1",
			// "page_size": 25,
			"agent_id":agent_id_rz,
			"start_date":start_date_lbt,
			"end_date":end_date_lbt
		}
		console.log(data);
		$.ajax({
			url:"/getOpLogList",
			type:"get",
			data:data,
			success:function(data){
				console.log(data);
				//等待遍历(权限不足)
				var html = "";
				$.each(data.data.data,function(i,value){
					html+="<tr id= 'tr_" + i + "'>"+	
					"<td class='td_1'>"+value.agent_id+"</td>"+
					"<td class='td_2'>"+value.created_at+"</td>"+
					"<td class='td_3'>"+value.created_at+"</td>"+
					"<td class='td_4'>"+value.op_log+"</td>"+
					"</tr>";
					$("#tbod_li_rz").html(html);
				});
			}
		});
	})





});